package com.xidian.zhiancloud.service.emergencyManagement;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.EmergencyMaterialsInventoryManagementMapper;
import com.xidian.zhiancloud.dao.EmergencyPlanExecMapper;
import com.xidian.zhiancloud.dao.EmergencyPlanManagementMapper;
import com.xidian.zhiancloud.dao.syset.SysUserMapper;
import com.xidian.zhiancloud.dao.syset.usermanage.OrganizationMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.*;
import com.xidian.zhiancloud.model.syset.Organization;
import com.xidian.zhiancloud.model.syset.SysUser;
import com.xidian.zhiancloud.util.zyf.StringUtils;
import com.xidian.zhiancloud.vo.emergencyManagement.EmergencyPlanExecVO;
import com.xidian.zhiancloud.vo.emergencyManagement.EmergencyTeamManagementDTOVO;
import com.xidian.zhiancloud.vo.emergencyManagement.EmergencyTeamManagementVO;
import com.xidian.zhiancloud.vo.emergencyManagement.PersonnelInformationVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Summerless
 * @Date: 2021/3/30 21:31
 */
@Service
public class EmergencyPlanExecService extends ServiceImpl<EmergencyPlanExecMapper, EmergencyPlanExec> implements IService<EmergencyPlanExec> {

    @Autowired
    private EmergencyPlanManagementMapper emergencyPlanManagementMapper;

    @Autowired
    private EmergencyPlanExecMapper emergencyPlanExecMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private OrganizationMapper organizationMapper;

    public List<EmergencyPlanExecVO> getListById(Long id) {
        QueryWrapper<EmergencyPlanExec> queryWrapper=new QueryWrapper<EmergencyPlanExec>();
        queryWrapper.eq("emergency_plan_id",id);
        List<EmergencyPlanExec> emergencyPlanExecList=emergencyPlanExecMapper.selectList(queryWrapper);

        List<EmergencyPlanExecVO> voList=new LinkedList<>();
        for (int i = 0; i < emergencyPlanExecList.size(); i++) {
            EmergencyPlanExecVO vos=new EmergencyPlanExecVO();
            BeanUtils.copyProperties(emergencyPlanExecList.get(i),vos);
            EmergencyPlanManagement emergencyPlanManagement=emergencyPlanManagementMapper.selectById(id);
            vos.setPlanName(emergencyPlanManagement==null?"该预案不存在":emergencyPlanManagement.getName());
            SysUser adder= sysUserMapper.selectById(vos.getStartUser());
            vos.setStartUserName(adder==null?"该用户不存在":adder.getName());
            SysUser ender= sysUserMapper.selectById(vos.getEndUser());
            vos.setEndUserName(ender==null?"该用户不存在":ender.getName());
            voList.add(vos);
        }
    return voList;
    }

}
